﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using Jquery.Modle;
using Jquery.IDAL;
namespace Jquery.DAL
{
    public class DBjquery : DbContext
    {
        public DbSet<Action> Actions { get; set; }
        public DbSet<Controller> Controllers { get; set; }
        public DbSet<JqueryFunctionType> JqueryFunctionTypes { get; set; }
        public DbSet<JqueryMethod> JqueryMethods { get; set; }
        public DbSet<JqueryMethodExample> JqueryMethodExamples { get; set; }
        public DbSet<JqueryMethodTag> JqueryMethodTags { get; set; }
        public DbSet<MemberShipGradingSystem> MemberShipGradingSystems { get; set; }
        public DbSet<MethodComment> MethodComments { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<RoleController> RoleControllers { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<UserInfo> UserInfos { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }

        /// <summary>
        /// 初始化库表时候约束 POCO方式的 约束
        /// </summary>
        /// <param name="b"></param>
        protected override void OnModelCreating(DbModelBuilder b)
        {
            base.OnModelCreating(b);
            b.Entity<Action>().Property(c => c.ActionId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired();
            b.Entity<Action>().Property(c => c.ActionName).HasMaxLength(50).IsRequired();
        }
    }
}